package com.example.chesswithnet.Controller;


import com.example.chesswithnet.Dao.UserDao;
import com.example.chesswithnet.Entity.User;
import javafx.fxml.FXML;
import javafx.scene.control.Alert;
import javafx.scene.control.TextField;

import java.sql.SQLException;

public class ForgetPass extends BaseController {

    @FXML
    private TextField account;
    @FXML
    private TextField phone;
    private String accountText;
    private String phoneText;

    public void onBtnForgetPassClick() throws SQLException {

        accountText = account.getText();
        phoneText = phone.getText();
        if(accountText.trim().isEmpty()){
            alert(Alert.AlertType.WARNING,"账号不能为空");
            return;
        }else if(phoneText.trim().isEmpty()){
            alert(Alert.AlertType.WARNING,"手机号不能为空");
            return;
        }
        User user = new UserDao().forgetPass(accountText,phoneText);
        if(user == null) {
            alert(Alert.AlertType.ERROR,"账号或者手机号错误");
            return;
        }else {
            alert(Alert.AlertType.CONFIRMATION,"找回密码为："+user.getPassword());
            return;
        }

    }

}
